const express = require('express')
const app = express()
const config = require('./config/index')
const bodyParser = require('body-parser')
const chalk = require('chalk')
const cookieParase = require('cookie-parser')
const port = config.initPort
const passport = require('passport')
const logger = require('./utils/logger')
const path = require('path')
const expressSession = require('express-session')
const initRouter = require('./routers/apiInit')
app.use(expressSession(config.session))
app.use(cookieParase())
app.use(logger.netLog())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(passport.initialize())
// view engine setup
app.set('views', path.join(__dirname, './views'));
app.set('view engine', 'ejs');
app.use(express.static(path.resolve(__dirname, 'static')))
// require('./utils/passport')(passport)
// app.use('/', function (req, res) {
//   res.send('hello world')
// })
app.use('/', initRouter);
app.listen(port, err => {
  if (!err) {
    console.log(chalk.blue(`Initialization mode in progress...... localhost:${port}`))
  } else {
    console.log(chalk.red(err))
  }
})